using System.Collections.Generic;

namespace GeoAzure.Core
{
    public class DeletionContext<T>
        where T : class
    {
        private readonly IndexEntry<T> _entry;
        private readonly int _targetLevel;
        private IList<TreeNode<T>> _deletedNodes;

        internal DeletionContext(IndexEntry<T> entry, int targetLevel)
            : this(entry, targetLevel, null)
        {
            _deletedNodes = new List<TreeNode<T>>();
        }

        internal DeletionContext(IndexEntry<T> entry, int targetLevel, DeletionContext<T> context)
        {
            _entry = entry;
            _targetLevel = targetLevel;
            if (context != null)
                _deletedNodes = context.DeletedNodes;
        }

        internal IndexEntry<T> Entry
        {
            get { return _entry; }
        }

        public int TargetLevel
        {
            get { return _targetLevel; }
        }

        internal IList<TreeNode<T>> DeletedNodes
        {
            get { return _deletedNodes; }
        }

        public void AddDeletedNode(TreeNode<T> treeNode)
        {
            if (DeletedNodes == null)
                _deletedNodes = new List<TreeNode<T>>();
            DeletedNodes.Add(treeNode);
        }
    }
}